package com.wiserun.RestFul.controller;


import com.wiserun.RestFul.model.Organization;
import com.wiserun.RestFul.model.UserDeptVO;
import com.wiserun.RestFul.service.*;
import com.wiserun.common.model.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;

/**
 *对外提供接口，访问内部数据，目前是给泛微提供组织机构的信息：
 * 1.员工信息包含员工基本信息和员工的部门信息
 * 2.组织机构包括所有的组织机构详情
 */
@RestController
@RequestMapping("/getInfo")
public class GetInfoController {

    @Autowired
    private PncsUserService pncsUserService;


    @Autowired
    private PncsOrganizationService pncsOrganizationService;

    /**
     * 获取人员信息
     * @param request
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "/getAllUsers", method = {RequestMethod.GET})
    @ResponseBody
    public ResponseData getAllUsers(HttpServletRequest request) throws ParseException {
        List<UserDeptVO> allUsers = pncsUserService.getAllUsers();
        ResponseData rd = new ResponseData();//返回前台数据
        rd.setCode(200);
        rd.setMessage("success,共查询到"+allUsers.size()+"条记录");
        rd.setData(allUsers);
        return  rd;
    }

    /**
     * 获取组织机构
     * @param request
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "/getAllOrganizations", method = {RequestMethod.GET})
    @ResponseBody
    public ResponseData getAllOrganizations(HttpServletRequest request) throws ParseException {
        List<Organization> organizations = pncsOrganizationService.getOrganization();
        ResponseData rd = new ResponseData();//返回前台数据
        rd.setCode(200);
        rd.setMessage("success,共查询到"+organizations.size()+"条记录");
        rd.setData(organizations);
        return  rd;
    }


}
